<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Shop extends CI_Controller {
	
	private $tab = 'shop';
	
	function __construct(){
		parent::__construct();
	}
	
	function prolist(){
		$per_page  = intval($this->input->get('per_page'));
		$per_page = $per_page ? $per_page : 0;
		$page_size = 10;
		$parms     = array(
			'pname' => trim($this->input->get('pname')),
			'ptype' => intval($this->input->get('type_id')),
			'ptui'  => intval($this->input->get('ptui')),
			'ptuan'	=> intval($this->input->get('ptuan')),
			'phot'	=> intval($this->input->get('phot')),
			'prob'	=> intval($this->input->get('prob')),
		);
		
		$data = array();
		$pdata = array(
			'page' => $per_page,
			'page_size' => $page_size,
			'where' => $parms
		);
		$this->load->model('Shop_model');
		
		$data = $this->Shop_model->pageData($pdata);
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/shop/prolist?pname='.$parms['pname'].'&ptype='.$parms['ptype'].'&ptui='.$parms['ptui'].'&ptuan='.$parms['ptuan'].'&phot='.$parms['phot'].'&prob='.$parms['prob'];
		$config['total_rows'] = $data['count'];
		$config['per_page'] = $page_size; 
		$this->pagination->initialize($config); 
		
		$data['vars'] = $this->Shop_model->arrays();
		$data['parms'] = $parms;
		$data['title'] = ' 商品列表';
		
		$data['tab'] 	= $this->tab;
		$data['sub'] 	= 'prolist';
		
		$this->load->view('/sys_admin/shop/shop_product_list', $data);
		
	}
	
	
	function view($id=''){
		$id = intval($id);
		$this->load->model('Shop_model');
		$data['vars'] = $this->Shop_model->arrays();
		if ($id>0){
			$data['info'] = $this->Shop_model->getOne($id);
		}
		
		$data['tab'] 	= $this->tab;
		$data['sub'] 	= 'shop_add';
		
		$this->load->view('/sys_admin/shop/shop_product_view', $data);
	}
	
	function toset(){
		$id = intval($this->input->post('id'));
		$data = array(
			'pname' => $this->input->post('pname'),
			'ptype' => $this->input->post('ptype'),
			'pmoney' => $this->input->post('pmoney'),
			'pcredit' => $this->input->post('pcredit'),
			'pvipcredit' => $this->input->post('pvipcredit'),
			'pdesc' => $this->input->post('pdesc'),
			'pstatus' => $this->input->post('pstatus'),
			'pvip' => $this->input->post('pvip'),
			'ptui' => $this->input->post('ptui'),
			'ptuan' => $this->input->post('ptuan'),
			'prate' => $this->input->post('prate'),
			'phot' => $this->input->post('phot'),
			'pconvert' => $this->input->post('pconvert'),
			'prob' => $this->input->post('prob'),
			'probstart' => $this->input->post('probstart') ? strtotime($this->input->post('probstart')):0,
			'psurp' => $this->input->post('psurp'),
		);
		$config['upload_path'] = 'static/uploads/shop/';
		$config['allowed_types'] = 'jpg|png';
		$config['file_name'] = uniqid();
		$config['overwrite'] = true;
		$config['max_size'] = '512';
		$config['max_width']  = '2048';
		$config['max_height']  = '3000';
		$this->load->library('upload', $config);
		$this->load->library('image_lib');
		if(isset($_FILES['pimg']) && $_FILES['pimg']['name'] != ''){
			if($this->upload->do_upload('pimg')){
				$tmp = $this->upload->data();
				$data['pimg'] = '/static/uploads/shop/'.$config['file_name'].$tmp['file_ext'];
			}else{
				$this->js->alert('图片上传失败');
				$this->js->go('');
				exit;
				//echo json_encode($ret);exit;
			}
		}
		
		$this->load->model('Shop_model');
		if ($id>0){
			$ret = $this->Shop_model->update($data,array('id'=>$id));
		}else{
			
			$ret = $this->Shop_model->add($data);
		}
		if ($ret) {
			$this->js->alert('操作成功');
			$this->js->go('/sys_admin/shop/prolist');
		}
	}
	
	
	function order(){
		$per_page  = intval($this->input->get('per_page'));
		$per_page = $per_page ? $per_page : 0;
		$page_size = 10;
		
		$data = array();
		
		$pdata = array(
			'page' => $per_page,
			'page_size' => $page_size,
			'where' => array(
				'username' => $this->input->get('username'),
				'pid' => $this->input->get('pid'),
				'fstatus' => isset($_GET['fstatus']) ? $this->input->get('fstatus') : -1,
				'strtime' => $this->input->get('strtime'),
				'endtime' => $this->input->get('endtime'),
			)
		);
		$this->load->model('Shop_model');
		$this->load->model('User_model');
		
		$data = $this->Shop_model->orderPageList($pdata);
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/shop/order?username='.$pdata['where']['username'].'&pid='.$pdata['where']['pid'].'&fstatus='.$pdata['where']['fstatus'].'&strtime='.$pdata['where']['strtime'].'&endtime='.$pdata['where']['endtime'];
		$config['total_rows'] = $data['count'];
		$config['per_page'] = $page_size; 
		$this->pagination->initialize($config); 
		
		$data['kefu_list'] = $this->User_model->get_kefu_list();
		$data['vars'] = $this->Shop_model->arrays();
		$data['statusArr'] = array(0=>'未发货',1=>'已发货');
		$data['title'] = ' 订单列表';
		
		$data['tab'] 	= $this->tab;
		$data['sub'] 	= 'order';
		
		$this->load->view('/sys_admin/shop/shop_order_list', $data);
	}
	
	function order_excel(){
		$pdata = array(
			'page' => 0,
			'page_size' => 9999,
			'where' => array(
				'username' => $this->input->get('username'),
				'pid' => $this->input->get('pid'),
				'fstatus' => isset($_GET['fstatus']) ? $this->input->get('fstatus') : -1,
				'strtime' => $this->input->get('strtime'),
				'endtime' => $this->input->get('endtime'),
			)
		);
		$this->load->model('Shop_model');
		$data = $this->Shop_model->orderPageList($pdata);
		$this->load->library('PHPExcel');
		$this->load->library('PHPExcel/IOFactory'); 
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("商城订单")->setDescription(COMPANY_NAME); 
		$objPHPExcel->setActiveSheetIndex(0);
		$titles = array("ID", "用户名", "客服", "商品编号", "商品名称", "数量", "积分", "收货人","收货地址", "收货人电话", "邮编", 
						"兑换时间","状态");
		for($i = 0; $i < count($titles); $i ++){
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $titles[$i]);
		}
		$orderlist = $data['list'];
		$this->load->model('User_model');
		$kefu_list = $this->User_model->get_kefu_list();
		$statusArr = array(0=>'未发货',1=>'已发货');
		for($i = 0; $i < count($orderlist); $i++){
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $i+2, $orderlist[$i]['id']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $i+2, $orderlist[$i]['username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $i+2, $kefu_list[$orderlist[$i]['kefu_userid']]['username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $i+2, $orderlist[$i]['pid']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $i+2, $orderlist[$i]['pname']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $i+2, $orderlist[$i]['pnum']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $i+2, $orderlist[$i]['total_price']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $i+2, $orderlist[$i]['get_name']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $i+2, $orderlist[$i]['get_address']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $i+2, $orderlist[$i]['get_phone']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $i+2, $orderlist[$i]['get_pc']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11, $i+2, date('Y-m-d H:i:s', $orderlist[$i]['add_time']));
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12, $i+2, $statusArr[$orderlist[$i]['fstatus']]);
		}
		
		$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5'); 
		//发送标题强制用户下载文件 
		header('Content-Type: application/vnd.ms-excel'); 
		header('Content-Disposition: attachment;filename="商城订单.xls"'); 
		header('Cache-Control: max-age=0'); 
		$objWriter->save('php://output'); 
	}
	
	function fahuo($id = 0){
		$id = intval($id);
		if ($id>0){
			$this->load->model('Shop_model');
			$res = $this->Shop_model->updateOrder(array('fstatus'=>1),array('id'=>$id));
			echo $res ? '操作成功':'操作失败';
		}
	}
	
	function notices(){
		//nid=10
		
		$this->load->model('site_model');
		$site = $this->site_model->get_site_one(array('url'=>'shop'));
		$nid = $site['id'];	
		
		//接收参数
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$title 				= $this->input->get('title');
		
		$data = array();
		if($title != ''){
			$data['where']['title'] = $title;
		}
		$data['where']['nid'] = $nid;
		$data['page_size']  = sys_admin_LIST_PAGE_SIZE;
		$data['page_start'] = (int)$per_page;
		$data['select'] 	= 1;
		$this->load->model('article_model');
		$vdata = $this->article_model->get_article_list($data);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/shop/notices?title='.$title;
		$config['total_rows'] = $vdata['article_count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$vdata['title'] 	= $title;
		$vdata['nid'] 		= $nid;
		
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'notices';
		
		$this->load->view('/sys_admin/shop/shop_notices', $vdata);
	}
	
	function notice_view($id=0){
		$id = intval($id);
		$vdata = array();
		if ($id>0) {
			$this->load->model('article_model');
	  		$vdata['info'] = $this->article_model->get_article_obj($id);
		}
		
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'notices_add';
		
		$this->load->view("/sys_admin/shop/shop_notice_view", $vdata);
	}
	
	function notice_set(){
		$id = intval($this->input->post('id'));
		$this->load->model('site_model');
		$site = $this->site_model->get_site_one(array('url'=>'shop'));
		$data['nid'] = $site['id'];	
			
		$data['title'] = $this->input->post('title');
		$data['ptime'] = $this->input->post('ptime')?strtotime($this->input->post('ptime')):time();
		$data['author'] = $this->input->post('author');
		$data['forder'] = $this->input->post('forder');
		$data['fsource'] = $this->input->post('fsource');
		$data['content'] = $this->input->post('content');
		
		$this->load->model('article_model');
		if ($id>0){
  			$ret = $this->article_model->update($id, $data);
		}else{
			$data['add_time'] 	= time();
	  		$data['addip'] 		= $this->js->get_ip();
	  		$ret = $this->article_model->add($data);
		}
		
		echo "<script>alert('操作成功');</script>";
	}
	
	function box_list(){
		$per_page  = intval($this->input->get('per_page'));
		$per_page = $per_page ? $per_page : 0;
		$page_size = 10;
		
		$data = array();
		
		$pdata = array(
			'page' => $per_page,
			'page_size' => $page_size,
			'where' => array(
				'is_open'=>1,
				'username' => $this->input->get('username'),
				'award_type' => $this->input->get('award_type'),
				'fstatus' => isset($_GET['fstatus']) ? $this->input->get('fstatus') : -1,
				'strtime' => $this->input->get('strtime'),
				'endtime' => $this->input->get('endtime'),
			)
		);
		$this->load->model('Shop_model');
		
		$data = $this->Shop_model->getBoxList($pdata);
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/shop/box_list?username='.$pdata['where']['username'].'&award_type='.$pdata['where']['award_type'].'&fstatus='.$pdata['where']['fstatus'].'&strtime='.$pdata['where']['strtime'].'&endtime='.$pdata['where']['endtime'];
		$config['total_rows'] = $data['count'];
		$config['per_page'] = $page_size; 
		$this->pagination->initialize($config); 
		
		//$data['kefu_list'] = $this->User_model->get_kefu_list();
		//$data['vars'] = $this->Shop_model->arrays();
		$data['statusArr'] = array(0=>'未发货',1=>'已发货');
		$data['title'] = ' 抽奖记录';
		
		$data['tab'] 	= $this->tab;
		$data['sub'] 	= 'lottery_record';
		
		$this->load->view('/sys_admin/shop/shop_box_list', $data);
	}
	
	
	function box_list_excle(){
		$data = array();
		
		$pdata = array(
			'limit' => 'all',
			'where' => array(
				'is_open'=>1,
				'username' => $this->input->get('username'),
				'award_type' => $this->input->get('award_type'),
				'fstatus' => isset($_GET['fstatus']) ? $this->input->get('fstatus') : -1,
				'strtime' => $this->input->get('strtime'),
				'endtime' => $this->input->get('endtime'),
			)
		);
		
		$this->load->model('Shop_model');
		$vdata = $this->Shop_model->getBoxList($pdata);
		
		$statusArr = array(0=>'未发货',1=>'已发货');
		$openArr = array(0=>'未打开',1=>'已打开');
		$awardTypeArr = array(0=>'无',1=>'积分',2=>'商品',3=>'VIP',4=>'钥匙(再来一次)');
		$colorArr = array(1=>'金',2=>'银',3=>'铜',4=>'铁',5=>'木');
		
		$this->load->library('PHPExcel');
		$this->load->library('PHPExcel/IOFactory'); 
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("抽奖记录")->setDescription(COMPANY_NAME); 
		$objPHPExcel->setActiveSheetIndex(0);
		$titles = array("编号", "用户名称", "箱子颜色", "打开积分", "是否打开","奖励类型","奖励商品","奖励积分","时间","状态");
		
		for($i = 0; $i < count($titles); $i ++){
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $titles[$i]);
		}
		
		$_list = $vdata['list'];
		
		for($i = 0; $i < count($_list); $i++){
			$award_type = $awardTypeArr[$_list[$i]['award_type']];
			if ($_list[$i]['award_type']==3){$award_type .= $_list[$i]['vip_time']/(3600*24)."天";}
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $i+2, $_list[$i]['id']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $i+2, $_list[$i]['username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $i+2, $colorArr[$_list[$i]['box_color']]);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $i+2, $_list[$i]['open_credit']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $i+2, $openArr[$_list[$i]['is_open']]);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $i+2, $award_type);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $i+2, $_list[$i]['pname']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $i+2, $_list[$i]['credit_value']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $i+2, date('Y-m-d H:i',$_list[$i]['add_time']));
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $i+2, $statusArr[$_list[$i]['fstatus']]);
		}
		
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="抽奖记录.xls"');
		header('Cache-Control: max-age=0');
		$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5'); 
		$objWriter->save('php://output');
		exit;
		
	}
	
	function boxfahuo($id = 0){
		$id = intval($id);
		if ($id>0){
			$this->load->model('Shop_model');
			$res = $this->Shop_model->updateBox(array('fstatus'=>1),array('id'=>$id));
			echo $res ? '操作成功':'操作失败';
		}
	}
	
	
	function scrollpic_list(){
		
		
		$this->load->model('scrollpic_model');
		$vdata = $this->scrollpic_model->shop_scrollpic_list();
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'shop_scrollpic';
		$this->load->view("/sys_admin/shop/shop_scrollpic_list",$vdata);
	}
	
	
	
	function add_scrollpic(){
		$this->load->helper(array('form'));
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'shop_scrollpic';
		
		$this->load->view("/sys_admin/shop_add_scrollpic",$vdata);
	}
	
	function edit_scrollpic($scrollpic_id){
		
		$this->load->helper(array('form'));
		$this->load->model('scrollpic_model');
  		$scrollpic = $this->scrollpic_model->get_shop_scrollpic_obj($scrollpic_id);
  		$vdata['scrollpic'] = $scrollpic;
  		
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'shop_scrollpic';
		
		$this->load->view("/sys_admin/shop/shop_edit_scrollpic",$vdata);
	}
	
	function do_scrollpic(){
		
		$url 		= $this->input->post('url');
		$title 		= $this->input->post('title');
		$forder 	= $this->input->post('forder');
			
		if(isset($_POST['act']) && $_POST['act'] == 'add'){
			
			//如果有上传图片，则先完成图片上传
			if(!file_exists(UPFILES_SCROLLPIC_IMG)){
				mkdir(UPFILES_SCROLLPIC_IMG);
			}
			$pic = "";
			if($_FILES['pic']['name'] != '')
			{ 
				$pic = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].time().rand());
				$tmpfn = $_FILES['pic']['name'];
				$pt=strrpos($tmpfn, ".");
				$retval=substr($tmpfn, $pt+1, strlen($tmpfn) - $pt);
				$pic.=".".$retval;
				$upfile = UPFILES_SCROLLPIC_IMG."/".$pic;
				if(is_uploaded_file($_FILES['pic']['tmp_name']))
					move_uploaded_file($_FILES['pic']['tmp_name'],$upfile);
			}
			
			$this->load->helper(array('form'));
			$this->load->library('form_validation');
			$this->form_validation->set_rules('url', 				'URL', 		'trim|min_length[1]|max_length[100]');	
			$this->form_validation->set_rules('title', 				'标题', 		'required|trim|min_length[1]|max_length[50]');
			$this->form_validation->set_rules('forder', 			'排序', 		'trim|integer|min_length[1]|max_length[20]');
			if ($this->form_validation->run() == FALSE){
	   			$this->load->view('/sys_admin/shop/shop_add_scrollpic');
	   			return;
	  		}
	  		
	  		$data['url'] 		= $url;
	  		$data['title'] 		= $title;
	  		$data['forder'] 	= $forder;
	  		$data['pic'] 		= $pic;
	  		$data['add_time'] 	= time();
	  		$this->load->model('scrollpic_model');
	  		$scrollpic_id = $this->scrollpic_model->add_shop_scrollpic($data);
	  		
	  		header("location:/sys_admin/shop/scrollpic_list");
			$this->load->model('log_model');$this->log_model->add_log('[添加]商城滚动图片]['.$title.']');
	   		exit;
		}else if(isset($_POST['act']) && $_POST['act'] == 'edit'){
			$id 		= $this->input->post('id');
			$bpic 		= $this->input->post('bpic');
			
			$pic = "";
			if($_FILES['pic']['name'] != ''){ 
				$pic = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].time().rand());
				$tmpfn = $_FILES['pic']['name'];
				$pt=strrpos($tmpfn, ".");
				$retval=substr($tmpfn, $pt+1, strlen($tmpfn) - $pt);
				$pic.=".".$retval;
				$upfile = UPFILES_SCROLLPIC_IMG."/".$pic;
				if(is_uploaded_file($_FILES['pic']['tmp_name']))
					move_uploaded_file($_FILES['pic']['tmp_name'],$upfile);
			}
			$pic = $pic?$pic:$bpic;
			
			$this->load->helper(array('form'));
			$this->load->library('form_validation');
			$this->form_validation->set_rules('id', 				'ID', 		'required');
			$this->form_validation->set_rules('url', 				'URL', 		'trim|min_length[1]|max_length[100]');	
			$this->form_validation->set_rules('title', 				'标题', 		'required|trim|min_length[1]|max_length[50]');
			$this->form_validation->set_rules('forder', 			'排序', 		'trim|integer|min_length[1]|max_length[20]');
			if ($this->form_validation->run() == FALSE){
	   			$this->load->view('/sys_admin/shop/shop_add_scrollpic');
	   			return;
	  		}
	  		
	  		$data['url'] 		= $url;
	  		$data['title'] 		= $title;
	  		$data['forder'] 	= $forder;
	  		$data['pic'] 		= $pic;
	  		$this->load->model('scrollpic_model');
	  		$scrollpic_id = $this->scrollpic_model->update_shop_scrollpic($id, $data);
	  		
	  		header("location:/sys_admin/shop/scrollpic_list");
	  		$this->load->model('log_model');$this->log_model->add_log('[修改][商城滚动图片]'.'ID=='.$id);
	   		exit;
		}
	}
	
	function remove_scrollpic(){
		$id 				= $this->input->post('id');
  		$data["is_del"]		= 1;
  		$this->load->model('scrollpic_model');
		echo  $this->scrollpic_model->update_shop_scrollpic($id, $data);
		$this->load->model('log_model');$this->log_model->add_log('[删除][商城动图片]');
	}
	
	function order_show(){
		$this->load->model('shop_model');
		$id = $this->input->post('id');
		$data["is_show"]		= $this->input->post('is_show');
		$where['id'] = $id;
		echo  $this->shop_model->updateOrder($data,$where);
	}
	
	
	
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Shop extends CI_Controller {
    
	private $tab = 'shop';
	
	function __construct(){
		parent::__construct();
	}
	
	function prolist(){
		$per_page  = intval($this->input->get('per_page'));
		$per_page = $per_page ? $per_page : 0;
		$page_size = 10;
		$parms     = array(
			'pname' => trim($this->input->get('pname')),
			'ptype' => intval($this->input->get('type_id')),
			'ptui'  => intval($this->input->get('ptui')),
			'ptuan'	=> intval($this->input->get('ptuan')),
			'phot'	=> intval($this->input->get('phot')),
			'prob'	=> intval($this->input->get('prob')),
		);
		
		$data = array();
		$pdata = array(
			'page' => $per_page,
			'page_size' => $page_size,
			'where' => $parms
		);
		$this->load->model('Shop_model');
		
		$data = $this->Shop_model->pageData($pdata);
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/shop/prolist?pname='.$parms['pname'].'&ptype='.$parms['ptype'].'&ptui='.$parms['ptui'].'&ptuan='.$parms['ptuan'].'&phot='.$parms['phot'].'&prob='.$parms['prob'];
		$config['total_rows'] = $data['count'];
		$config['per_page'] = $page_size; 
		$this->pagination->initialize($config); 
		
		$data['vars'] = $this->Shop_model->arrays();
		$data['parms'] = $parms;
		$data['title'] = ' 商品列表';
		
		$data['tab'] 	= $this->tab;
		$data['sub'] 	= 'prolist';
		
		$this->load->view('/sys_admin/shop/shop_product_list', $data);
		
	}
	
	
	function view($id=''){
		$id = intval($id);
		$this->load->model('Shop_model');
		$data['vars'] = $this->Shop_model->arrays();
		if ($id>0){
			$data['info'] = $this->Shop_model->getOne($id);
		}
		
		$data['tab'] 	= $this->tab;
		$data['sub'] 	= 'shop_add';
		
		$this->load->view('/sys_admin/shop/shop_product_view', $data);
	}
	
	function toset(){
		$id = intval($this->input->post('id'));
		$data = array(
			'pname' => $this->input->post('pname'),
			'ptype' => $this->input->post('ptype'),
			'pmoney' => $this->input->post('pmoney'),
			'pcredit' => $this->input->post('pcredit'),
			'pvipcredit' => $this->input->post('pvipcredit'),
			'pdesc' => $this->input->post('pdesc'),
			'pstatus' => $this->input->post('pstatus'),
			'pvip' => $this->input->post('pvip'),
			'ptui' => $this->input->post('ptui'),
			'ptuan' => $this->input->post('ptuan'),
			'prate' => $this->input->post('prate'),
			'phot' => $this->input->post('phot'),
			'pconvert' => $this->input->post('pconvert'),
			'prob' => $this->input->post('prob'),
			'probstart' => $this->input->post('probstart') ? strtotime($this->input->post('probstart')):0,
			'psurp' => $this->input->post('psurp'),
		);
		$config['upload_path'] = 'static/uploads/shop/';
		$config['allowed_types'] = 'jpg|png';
		$config['file_name'] = uniqid();
		$config['overwrite'] = true;
		$config['max_size'] = '512';
		$config['max_width']  = '2048';
		$config['max_height']  = '3000';
		$this->load->library('upload', $config);
		$this->load->library('image_lib');
		if(isset($_FILES['pimg']) && $_FILES['pimg']['name'] != ''){
			if($this->upload->do_upload('pimg')){
				$tmp = $this->upload->data();
				$data['pimg'] = '/static/uploads/shop/'.$config['file_name'].$tmp['file_ext'];
			}else{
				$this->js->alert('图片上传失败');
				$this->js->go('');
				exit;
				//echo json_encode($ret);exit;
			}
		}
		
		$this->load->model('Shop_model');
		if ($id>0){
			$ret = $this->Shop_model->update($data,array('id'=>$id));
		}else{
			
			$ret = $this->Shop_model->add($data);
		}
		if ($ret) {
			$this->js->alert('操作成功');
			$this->js->go('/sys_admin/shop/prolist');
		}
	}
	
	
	function order(){
		$per_page  = intval($this->input->get('per_page'));
		$per_page = $per_page ? $per_page : 0;
		$page_size = 10;
		
		$data = array();
		
		$pdata = array(
			'page' => $per_page,
			'page_size' => $page_size,
			'where' => array(
				'username' => $this->input->get('username'),
				'pid' => $this->input->get('pid'),
				'fstatus' => isset($_GET['fstatus']) ? $this->input->get('fstatus') : -1,
				'strtime' => $this->input->get('strtime'),
				'endtime' => $this->input->get('endtime'),
			)
		);
		$this->load->model('Shop_model');
		$this->load->model('User_model');
		
		$data = $this->Shop_model->orderPageList($pdata);
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/shop/order?username='.$pdata['where']['username'].'&pid='.$pdata['where']['pid'].'&fstatus='.$pdata['where']['fstatus'].'&strtime='.$pdata['where']['strtime'].'&endtime='.$pdata['where']['endtime'];
		$config['total_rows'] = $data['count'];
		$config['per_page'] = $page_size; 
		$this->pagination->initialize($config); 
		
		$data['kefu_list'] = $this->User_model->get_kefu_list();
		$data['vars'] = $this->Shop_model->arrays();
		$data['statusArr'] = array(0=>'未发货',1=>'已发货');
		$data['title'] = ' 订单列表';
		
		$data['tab'] 	= $this->tab;
		$data['sub'] 	= 'order';
		
		$this->load->view('/sys_admin/shop/shop_order_list', $data);
	}
	
	function order_excel(){
		$pdata = array(
			'page' => 0,
			'page_size' => 9999,
			'where' => array(
				'username' => $this->input->get('username'),
				'pid' => $this->input->get('pid'),
				'fstatus' => isset($_GET['fstatus']) ? $this->input->get('fstatus') : -1,
				'strtime' => $this->input->get('strtime'),
				'endtime' => $this->input->get('endtime'),
			)
		);
		$this->load->model('Shop_model');
		$data = $this->Shop_model->orderPageList($pdata);
		$this->load->library('PHPExcel');
		$this->load->library('PHPExcel/IOFactory'); 
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("商城订单")->setDescription(COMPANY_NAME); 
		$objPHPExcel->setActiveSheetIndex(0);
		$titles = array("ID", "用户名", "客服", "商品编号", "商品名称", "数量", "积分", "收货人","收货地址", "收货人电话", "邮编", 
						"兑换时间","状态");
		for($i = 0; $i < count($titles); $i ++){
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $titles[$i]);
		}
		$orderlist = $data['list'];
		$this->load->model('User_model');
		$kefu_list = $this->User_model->get_kefu_list();
		$statusArr = array(0=>'未发货',1=>'已发货');
		for($i = 0; $i < count($orderlist); $i++){
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $i+2, $orderlist[$i]['id']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $i+2, $orderlist[$i]['username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $i+2, $kefu_list[$orderlist[$i]['kefu_userid']]['username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $i+2, $orderlist[$i]['pid']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $i+2, $orderlist[$i]['pname']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $i+2, $orderlist[$i]['pnum']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $i+2, $orderlist[$i]['total_price']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $i+2, $orderlist[$i]['get_name']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $i+2, $orderlist[$i]['get_address']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $i+2, $orderlist[$i]['get_phone']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $i+2, $orderlist[$i]['get_pc']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11, $i+2, date('Y-m-d H:i:s', $orderlist[$i]['add_time']));
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12, $i+2, $statusArr[$orderlist[$i]['fstatus']]);
		}
		
		$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5'); 
		//发送标题强制用户下载文件 
		header('Content-Type: application/vnd.ms-excel'); 
		header('Content-Disposition: attachment;filename="商城订单.xls"'); 
		header('Cache-Control: max-age=0'); 
		$objWriter->save('php://output'); 
	}
	
	function fahuo($id = 0){
		$id = intval($id);
		if ($id>0){
			$this->load->model('Shop_model');
			$res = $this->Shop_model->updateOrder(array('fstatus'=>1),array('id'=>$id));
			echo $res ? '操作成功':'操作失败';
		}
	}
	
	function notices(){
		//nid=10
		
		$this->load->model('site_model');
		$site = $this->site_model->get_site_one(array('url'=>'shop'));
		$nid = $site['id'];	
		
		//接收参数
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$title 				= $this->input->get('title');
		
		$data = array();
		if($title != ''){
			$data['where']['title'] = $title;
		}
		$data['where']['nid'] = $nid;
		$data['page_size']  = sys_admin_LIST_PAGE_SIZE;
		$data['page_start'] = (int)$per_page;
		$data['select'] 	= 1;
		$this->load->model('article_model');
		$vdata = $this->article_model->get_article_list($data);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/shop/notices?title='.$title;
		$config['total_rows'] = $vdata['article_count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$vdata['title'] 	= $title;
		$vdata['nid'] 		= $nid;
		
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'notices';
		
		$this->load->view('/sys_admin/shop/shop_notices', $vdata);
	}
	
	function notice_view($id=0){
		$id = intval($id);
		$vdata = array();
		if ($id>0) {
			$this->load->model('article_model');
	  		$vdata['info'] = $this->article_model->get_article_obj($id);
		}
		
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'notices_add';
		
		$this->load->view("/sys_admin/shop/shop_notice_view", $vdata);
	}
	
	function notice_set(){
		$id = intval($this->input->post('id'));
		$this->load->model('site_model');
		$site = $this->site_model->get_site_one(array('url'=>'shop'));
		$data['nid'] = $site['id'];	
			
		$data['title'] = $this->input->post('title');
		$data['ptime'] = $this->input->post('ptime')?strtotime($this->input->post('ptime')):time();
		$data['author'] = $this->input->post('author');
		$data['forder'] = $this->input->post('forder');
		$data['fsource'] = $this->input->post('fsource');
		$data['content'] = $this->input->post('content');
		
		$this->load->model('article_model');
		if ($id>0){
  			$ret = $this->article_model->update($id, $data);
		}else{
			$data['add_time'] 	= time();
	  		$data['addip'] 		= $this->js->get_ip();
	  		$ret = $this->article_model->add($data);
		}
		
		echo "<script>alert('操作成功');</script>";
	}
	
	function box_list(){
		$per_page  = intval($this->input->get('per_page'));
		$per_page = $per_page ? $per_page : 0;
		$page_size = 10;
		
		$data = array();
		
		$pdata = array(
			'page' => $per_page,
			'page_size' => $page_size,
			'where' => array(
				'is_open'=>1,
				'username' => $this->input->get('username'),
				'award_type' => $this->input->get('award_type'),
				'fstatus' => isset($_GET['fstatus']) ? $this->input->get('fstatus') : -1,
				'strtime' => $this->input->get('strtime'),
				'endtime' => $this->input->get('endtime'),
			)
		);
		$this->load->model('Shop_model');
		
		$data = $this->Shop_model->getBoxList($pdata);
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/shop/box_list?username='.$pdata['where']['username'].'&award_type='.$pdata['where']['award_type'].'&fstatus='.$pdata['where']['fstatus'].'&strtime='.$pdata['where']['strtime'].'&endtime='.$pdata['where']['endtime'];
		$config['total_rows'] = $data['count'];
		$config['per_page'] = $page_size; 
		$this->pagination->initialize($config); 
		
		//$data['kefu_list'] = $this->User_model->get_kefu_list();
		//$data['vars'] = $this->Shop_model->arrays();
		$data['statusArr'] = array(0=>'未发货',1=>'已发货');
		$data['title'] = ' 抽奖记录';
		
		$data['tab'] 	= $this->tab;
		$data['sub'] 	= 'lottery_record';
		
		$this->load->view('/sys_admin/shop/shop_box_list', $data);
	}
	
	
	function box_list_excle(){
		$data = array();
		
		$pdata = array(
			'limit' => 'all',
			'where' => array(
				'is_open'=>1,
				'username' => $this->input->get('username'),
				'award_type' => $this->input->get('award_type'),
				'fstatus' => isset($_GET['fstatus']) ? $this->input->get('fstatus') : -1,
				'strtime' => $this->input->get('strtime'),
				'endtime' => $this->input->get('endtime'),
			)
		);
		
		$this->load->model('Shop_model');
		$vdata = $this->Shop_model->getBoxList($pdata);
		
		$statusArr = array(0=>'未发货',1=>'已发货');
		$openArr = array(0=>'未打开',1=>'已打开');
		$awardTypeArr = array(0=>'无',1=>'积分',2=>'商品',3=>'VIP',4=>'钥匙(再来一次)');
		$colorArr = array(1=>'金',2=>'银',3=>'铜',4=>'铁',5=>'木');
		
		$this->load->library('PHPExcel');
		$this->load->library('PHPExcel/IOFactory'); 
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("抽奖记录")->setDescription(COMPANY_NAME); 
		$objPHPExcel->setActiveSheetIndex(0);
		$titles = array("编号", "用户名称", "箱子颜色", "打开积分", "是否打开","奖励类型","奖励商品","奖励积分","时间","状态");
		
		for($i = 0; $i < count($titles); $i ++){
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $titles[$i]);
		}
		
		$_list = $vdata['list'];
		
		for($i = 0; $i < count($_list); $i++){
			$award_type = $awardTypeArr[$_list[$i]['award_type']];
			if ($_list[$i]['award_type']==3){$award_type .= $_list[$i]['vip_time']/(3600*24)."天";}
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $i+2, $_list[$i]['id']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $i+2, $_list[$i]['username']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $i+2, $colorArr[$_list[$i]['box_color']]);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $i+2, $_list[$i]['open_credit']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $i+2, $openArr[$_list[$i]['is_open']]);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $i+2, $award_type);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $i+2, $_list[$i]['pname']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $i+2, $_list[$i]['credit_value']);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $i+2, date('Y-m-d H:i',$_list[$i]['add_time']));
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $i+2, $statusArr[$_list[$i]['fstatus']]);
		}
		
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="抽奖记录.xls"');
		header('Cache-Control: max-age=0');
		$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5'); 
		$objWriter->save('php://output');
		exit;
		
	}
	
	function boxfahuo($id = 0){
		$id = intval($id);
		if ($id>0){
			$this->load->model('Shop_model');
			$res = $this->Shop_model->updateBox(array('fstatus'=>1),array('id'=>$id));
			echo $res ? '操作成功':'操作失败';
		}
	}
	
	
	function scrollpic_list(){
		
		
		$this->load->model('scrollpic_model');
		$vdata = $this->scrollpic_model->shop_scrollpic_list();
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'shop_scrollpic';
		$this->load->view("/sys_admin/shop/shop_scrollpic_list",$vdata);
	}
	
	
	
	function add_scrollpic(){
		$this->load->helper(array('form'));
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'shop_scrollpic';
		
		$this->load->view("/sys_admin/shop_add_scrollpic",$vdata);
	}
	
	function edit_scrollpic($scrollpic_id){
		
		$this->load->helper(array('form'));
		$this->load->model('scrollpic_model');
  		$scrollpic = $this->scrollpic_model->get_shop_scrollpic_obj($scrollpic_id);
  		$vdata['scrollpic'] = $scrollpic;
  		
		$vdata['tab'] 	= $this->tab;
		$vdata['sub'] 	= 'shop_scrollpic';
		
		$this->load->view("/sys_admin/shop/shop_edit_scrollpic",$vdata);
	}
	
	function do_scrollpic(){
		
		$url 		= $this->input->post('url');
		$title 		= $this->input->post('title');
		$forder 	= $this->input->post('forder');
			
		if(isset($_POST['act']) && $_POST['act'] == 'add'){
			
			//如果有上传图片，则先完成图片上传
			if(!file_exists(UPFILES_SCROLLPIC_IMG)){
				mkdir(UPFILES_SCROLLPIC_IMG);
			}
			$pic = "";
			if($_FILES['pic']['name'] != '')
			{ 
				$pic = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].time().rand());
				$tmpfn = $_FILES['pic']['name'];
				$pt=strrpos($tmpfn, ".");
				$retval=substr($tmpfn, $pt+1, strlen($tmpfn) - $pt);
				$pic.=".".$retval;
				$upfile = UPFILES_SCROLLPIC_IMG."/".$pic;
				if(is_uploaded_file($_FILES['pic']['tmp_name']))
					move_uploaded_file($_FILES['pic']['tmp_name'],$upfile);
			}
			
			$this->load->helper(array('form'));
			$this->load->library('form_validation');
			$this->form_validation->set_rules('url', 				'URL', 		'trim|min_length[1]|max_length[100]');	
			$this->form_validation->set_rules('title', 				'标题', 		'required|trim|min_length[1]|max_length[50]');
			$this->form_validation->set_rules('forder', 			'排序', 		'trim|integer|min_length[1]|max_length[20]');
			if ($this->form_validation->run() == FALSE){
	   			$this->load->view('/sys_admin/shop/shop_add_scrollpic');
	   			return;
	  		}
	  		
	  		$data['url'] 		= $url;
	  		$data['title'] 		= $title;
	  		$data['forder'] 	= $forder;
	  		$data['pic'] 		= $pic;
	  		$data['add_time'] 	= time();
	  		$this->load->model('scrollpic_model');
	  		$scrollpic_id = $this->scrollpic_model->add_shop_scrollpic($data);
	  		
	  		header("location:/sys_admin/shop/scrollpic_list");
			$this->load->model('log_model');$this->log_model->add_log('[添加]商城滚动图片]['.$title.']');
	   		exit;
		}else if(isset($_POST['act']) && $_POST['act'] == 'edit'){
			$id 		= $this->input->post('id');
			$bpic 		= $this->input->post('bpic');
			
			$pic = "";
			if($_FILES['pic']['name'] != ''){ 
				$pic = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].time().rand());
				$tmpfn = $_FILES['pic']['name'];
				$pt=strrpos($tmpfn, ".");
				$retval=substr($tmpfn, $pt+1, strlen($tmpfn) - $pt);
				$pic.=".".$retval;
				$upfile = UPFILES_SCROLLPIC_IMG."/".$pic;
				if(is_uploaded_file($_FILES['pic']['tmp_name']))
					move_uploaded_file($_FILES['pic']['tmp_name'],$upfile);
			}
			$pic = $pic?$pic:$bpic;
			
			$this->load->helper(array('form'));
			$this->load->library('form_validation');
			$this->form_validation->set_rules('id', 				'ID', 		'required');
			$this->form_validation->set_rules('url', 				'URL', 		'trim|min_length[1]|max_length[100]');	
			$this->form_validation->set_rules('title', 				'标题', 		'required|trim|min_length[1]|max_length[50]');
			$this->form_validation->set_rules('forder', 			'排序', 		'trim|integer|min_length[1]|max_length[20]');
			if ($this->form_validation->run() == FALSE){
	   			$this->load->view('/sys_admin/shop/shop_add_scrollpic');
	   			return;
	  		}
	  		
	  		$data['url'] 		= $url;
	  		$data['title'] 		= $title;
	  		$data['forder'] 	= $forder;
	  		$data['pic'] 		= $pic;
	  		$this->load->model('scrollpic_model');
	  		$scrollpic_id = $this->scrollpic_model->update_shop_scrollpic($id, $data);
	  		
	  		header("location:/sys_admin/shop/scrollpic_list");
	  		$this->load->model('log_model');$this->log_model->add_log('[修改][商城滚动图片]'.'ID=='.$id);
	   		exit;
		}
	}
	
	function remove_scrollpic(){
		$id 				= $this->input->post('id');
  		$data["is_del"]		= 1;
  		$this->load->model('scrollpic_model');
		echo  $this->scrollpic_model->update_shop_scrollpic($id, $data);
		$this->load->model('log_model');$this->log_model->add_log('[删除][商城动图片]');
	}
	
	function order_show(){
		$this->load->model('shop_model');
		$id = $this->input->post('id');
		$data["is_show"]		= $this->input->post('is_show');
		$where['id'] = $id;
		echo  $this->shop_model->updateOrder($data,$where);
	}
	
	
	
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}